package de.ama.crawler;

import com.github.savvasdalkitsis.jtmdb.GeneralSettings;
import com.github.savvasdalkitsis.jtmdb.Log;
import de.ama.util.Util;
import de.ama.view.AppWindow;

import java.io.File;
import java.util.Locale;

/**
 * Created by IntelliJ IDEA.
 * User: ama
 * Date: 14.02.11
 * Time: 17:59
 * To change this template use File | Settings | File Templates.
 */
public class Starter {


    public static void main(String[] args ){

        Config.get();

        GeneralSettings.setApiKey("741b59377536205e7d8960e441d68c06");
        GeneralSettings.setLogEnabled(true);
        GeneralSettings.setLogVerbosity(Log.Verbosity.ERROR);
        GeneralSettings.setAPILocale(new Locale("de","DE"));

        setProxy();

        loadDB();

        startGUI();

        startCrawler();

        Store.get().updateAllEntrys();

        AppWindow.get().sort();


    }

    private static void startCrawler() {
        File[] roots = File.listRoots();
        for (File root: roots) {
            File dir = new File(root,Config.get().getRootdir());
            if (dir.exists() && dir.isDirectory()) {
                Crawler c = new Crawler(dir);
            }
        }
    }

    private static void setProxy() {
        if(Util.isEmpty(Config.get().getProxy_host()))  return;

        System.getProperties().setProperty("http.proxyHost",Config.get().getProxy_host());
        System.getProperties().setProperty("http.proxyPort",Config.get().getProxy_port());
        Log.log("http.proxyHost set to "+System.getProperty("http.proxyHost"));
        Log.log("http.proxyPort set to "+System.getProperty("http.proxyPort"));
    }

    private static void startGUI() {
        AppWindow frame = new AppWindow();
        frame.start();
    }

    private static void loadDB() {
        Store store = new Store();
    }

}
